//
//  YSBookFileManager.m
//  YSBookRead
//
//  Created by Kyson on 2018/11/6.
//  Copyright © 2018 YangShen. All rights reserved.
//

#import "YSBookFileManager.h"

#define kBookCachePath [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES).firstObject stringByAppendingPathComponent:@"bookcaches"]

@implementation YSBookFileManager

/// 获取文件路径
+ (NSString *)filePathWithFolderName:(NSString *)folderName fileName:(NSString *)fileName {
    NSString *foldPath = [kBookCachePath stringByAppendingPathComponent:folderName];
    
    NSFileManager *fm = [NSFileManager defaultManager];
    if (![fm fileExistsAtPath:foldPath]) {
        [fm createDirectoryAtPath:foldPath withIntermediateDirectories:YES attributes:nil error:nil];
    }
    
    NSString *path = [foldPath stringByAppendingPathComponent:fileName];
    return path;
}

/// 文件是否存在
+ (BOOL)fileIsExist:(NSString *)folderName fileName:(NSString *)fileName {
    NSString *path = [self filePathWithFolderName:folderName fileName:fileName];
    return [self fileIsExist:path];
}

+ (BOOL)fileIsExist:(NSString *)filePath {
    NSFileManager *fm = [NSFileManager defaultManager];
    return [fm fileExistsAtPath:filePath];
}

@end
